package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.NetworkStorageCharge;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.vo.NetworkStorageChargeVo;
import com.ruoyi.logistic.service.NetworkStorageChargeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/storageCharge")
@RestController
@Api(tags = "网点财务_包仓费其他费用结算")
public class NetworkStorageChargeController {
    @Autowired
    private NetworkStorageChargeService networkStorageChargeService;
    @Autowired
    private TableService tableService;
    @ApiOperation("显示包仓费其他费用结算列表")
    @GetMapping("/selectAll")
    public R selectAll(PageDate pageDate){
        List<NetworkStorageCharge> networkStorageCharges = networkStorageChargeService.selectAll(pageDate);
        if (networkStorageCharges == null || networkStorageCharges.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkStorageCharges));
        }
    }
    @ApiOperation("添加包仓费其他费用结算")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkStorageCharge networkStorageCharge){
        Boolean isAdd = networkStorageChargeService.insert(networkStorageCharge);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改包仓费其他费用结算")
    @PostMapping("/update")
    public R update(@RequestBody NetworkStorageCharge networkStorageCharge){
        Boolean isUpdate = networkStorageChargeService.update(networkStorageCharge);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除包仓费其他费用结算")
    @PostMapping("/deleteById")
    public R deleteById(@Param("ids") Integer [] ids){
        Boolean isDelete = networkStorageChargeService.deleteByIds(ids);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("搜索包仓费其他费用结算")
    @PostMapping("/search")
    public R search(@RequestBody NetworkStorageChargeVo networkStorageChargeVo){
        List<NetworkStorageCharge> networkStorageCharges = networkStorageChargeService.search(networkStorageChargeVo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkStorageCharge());
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        jsonObject.put("list", PageInfo.info(networkStorageCharges));
        jsonObject.put("fields", fieldList);
        if (networkStorageCharges == null || networkStorageCharges.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }
}
